package base.search;

/**
 * 统计字符串出现的个数
 *
 */
public class AccountWordNumber {

    public static void main(String[] args){
        countWord("HelloWord   HelloABCHe  llo","Hello");

    }

    /**
     *
     * @param str
     * @param word
     */
    public static void countWord(String str,String word){
        int count = 0;
        String substr;
        int index;
        while(str.contains(word)){
            count++;
            index = str.indexOf(word);
            substr = str.substring(index + word.length());
            str = substr;
            System.out.println("子串："+str);
        }
        System.out.println("count:" + count);
    }


}
